﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace T3task
{
    class Program
    {
        static void Main(string[] args)
        {
            
            SqlDataReader reader = null;
            try
            {
                //所有游戏查询
                string sql = "select NO,Name,price,stock,price*stock Total from Games";
                reader = DBHelper.Select(sql);
                Console.WriteLine("序号\t游戏名称\t游戏介绍\t库存数量\t小计");
                Console.WriteLine("+------------------------------------------------------");
                while (reader.Read())
                {
                    Console.WriteLine("{0}\t{1}\t{2:C}元\t\t{3}\t{4:C}元",
                                           reader["NO"],
                                            reader["Name"],
                                             reader["price"],
                                              reader["stock"],
                                               reader["Total"]

                        );

                }
                reader.Close();
                Console.WriteLine("+------------------------------------------------------");
                //统计总金额
                string totalSql = "select sum(Price*Stock) from Games";
                Console.WriteLine("游戏总金额：{0:C}元", DBHelper.Exestu(totalSql));
            }
            catch (Exception ex)
            {
                //检测到异常，进行异常处理，防止应用程序崩溃，打印信息提示用户
                Console.WriteLine("加载产品列表时出现异常，请联系管理员！\n原因："+ex.Message);
            }
                
        }
    }
}
